<?php
class Login extends CustomerController {
    public function __construct() {
        parent::__construct();
    }
    
    public function index() {
        $this->_data["loadPage"]="verify/login_view";
        $this->_data["loadMenu"]="other/menu_view";
        $this->_data["titlePage"]="Đăng nhập";
        
        $this->_data["mess_succ"]=$this->session->flashdata("flash_mess");
        
        $this->load->model("mmodule");
        $tmp=$this->mmodule->listAll();
        if($tmp!=false)
        $this->_data["info_module"]=$tmp;
        
        if($this->input->post("btnSubmit")) {
            $u=$this->input->post("txtUsername");
            $p=md5($this->input->post("txtPass"));
            $this->load->model("muser");
            $data=$this->muser->login($u, $p);
            if(!$data)
                $this->_data["error"]="Username hay password không chính xác.";
            else {
                $this->load->model("mlevel");
                $level=$this->mlevel->getById($data["level_id"]);
                $sess=array(
                    "username"=>$data["u_username"],
                    "level"=>$level["level_name"],
                    "id"=>$data["u_id"]
                );
                $this->session->set_userdata($sess);
//                $this->session->set_flashdata("flash_mess", "Welcome ".$data["u_username"]);
                redirect(base_url()."customer/home/");
            }
        }
        
        $this->load->view($this->_data["path"], $this->_data);
    }
}
?>